package cn.wei.example.consumer;

import cn.wei.example.common.model.User;
import cn.wei.example.common.service.UserService;
import cn.wei.youvierpc.bootstrap.ComsumerBootstrap;
import cn.wei.youvierpc.config.RpcConfig;
import cn.wei.youvierpc.proxy.ServiceProxyFactory;
import cn.wei.youvierpc.utils.ConfigUtils;

import static cn.wei.youvierpc.proxy.ServiceProxyFactory.getMockProxy;

public class ConsumerExample {
    public static void main(String[] args) {
        ComsumerBootstrap.init();

        RpcConfig rpc = ConfigUtils.loadConfig(RpcConfig.class, "rpc");

        System.out.println(rpc);

        UserService userService = ServiceProxyFactory.getProxy(UserService.class);
        User user = new User();
        user.setName("youvie");

        User resultUser = userService.getUser(user);
        if (resultUser == null) {
            System.out.println("user == null");
        } else {
            System.out.println(resultUser.getName());
        }

        UserService userService1 = ServiceProxyFactory.getMockProxy(UserService.class);
        short number = userService1.getNumber();
        System.out.println(number);
    }
}
